package com.machinecontroller.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.machinecontroller.service.GuardService;
import com.machinecontroller.ui.MainActivity;

/**
 * 开机自启动APP
 * Created by zhangxuehui on 2017/12/14.
 */
public class BootBroadcastReceiver extends BroadcastReceiver{
    static  final String ACTION = "android.intent.action.BOOT_COMPLETED";
    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals(ACTION)){
            context.startActivity(new Intent(context, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
            //后边的XXX.class就是要启动的服务
            Intent service = new Intent(context, GuardService.class);
            context.startService(service);
            Log.v("TAG", "开机自动服务自动启动.....");
        }
    }
}
